﻿namespace QMVnSoft.DAL
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CTSXDataAccess
    {
        public int CheckInvoiceLock(string ps_Subsidiary, string ps_UserName, object ps_InvoiceOrder)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Check", null) };
            values[3].Direction = ParameterDirection.Output;
            values[3].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CheckInvoiceLockedSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[3].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return num;
        }

        public int CheckInvoicePost(string ps_Subsidiary, string ps_UserName, object ps_InvoiceOrder)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Check", null) };
            values[3].Direction = ParameterDirection.Output;
            values[3].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CheckInvoicePostedSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[3].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return num;
        }

        public int CheckInvoiceStatus(string ps_Subsidiary, string ps_UserName, object ps_InvoiceOrder)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Check", null) };
            values[3].Direction = ParameterDirection.Output;
            values[3].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CheckInvoiceStatusSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[3].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return num;
        }

        public object Cong_So_Ct(string ps_Subsidiary, string ps_InvoiceCode, object pd_Ngay_Ct, object ps_So_Ct)
        {
            object obj2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ma_Ct", ps_InvoiceCode), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_So_Ct", ps_So_Ct) };
            values[3].Direction = ParameterDirection.InputOutput;
            values[3].SqlDbType = SqlDbType.NVarChar;
            values[3].Size = 20;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Cong_So_CtSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                obj2 = values[3].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return obj2;
        }

        public int CtSX_Pause_Delete(object ps_MasterKey)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter() };
            values[1].Direction = ParameterDirection.ReturnValue;
            values[1].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Pause_Delete";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[1].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }

        public object CtSX_Pause_Get(object ps_MasterKey)
        {
            object obj2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Huy", null) };
            values[1].Direction = ParameterDirection.Output;
            values[1].SqlDbType = SqlDbType.DateTime;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Pause_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                obj2 = values[1].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return obj2;
        }

        public int CtSX_Pause_Save(object ps_MasterKey, object pd_Ngay_Huy)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Huy", pd_Ngay_Huy), new SqlParameter("p_Result", SqlDbType.BigInt) };
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Pause_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[2].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }

        public bool Delete(string ps_UserName, object po_KeyCode)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", po_KeyCode), new SqlParameter("p_UserName", ps_UserName), new SqlParameter() };
            values[2].Direction = ParameterDirection.ReturnValue;
            values[2].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Delete";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                flag = ((int) values[2].Value) == 1;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return flag;
        }

        public bool DeleteDetailDataRow(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt0", po_KeyCode), new SqlParameter() };
            values[1].Direction = ParameterDirection.ReturnValue;
            values[1].SqlDbType = SqlDbType.Int;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX0_Delete";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                flag = ((int) values[1].Value) == 1;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return flag;
        }

        public DataTable GetDetailCommand(object ps_MasterKey)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt0", ps_MasterKey) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX1_CdVT_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return table2;
        }

        public DataSet GetDetailDataSet(string ps_InvoiceOrder)
        {
            DataSet set2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataSet dataSet = new DataSet();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX0_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataSet);
                AppDataAccess.CloseConnection(eZConnection);
                set2 = dataSet;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return set2;
        }

        public DataTable GetMasterCommand(object ps_ParentKey)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_ParentKey) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_CdVT_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return table2;
        }

        public DataRow GetMasterDataRow(string ps_InvoiceOrder)
        {
            DataRow row;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_One_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                if (dataTable.Rows.Count == 0)
                {
                    dataTable.Rows.Add(dataTable.NewRow());
                    dataTable.AcceptChanges();
                }
                row = dataTable.Rows[0];
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return row;
        }

        public DataTable GetMasterTable(string ps_Subsidiary, int pi_DaysFilter, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_So_Ct1, object ps_So_Ct2, object ps_Ma_Ct, object ps_Ma_YC, object ps_Ma_NN, object ps_Ma_Bp, object ps_Ma_Hd, object ps_Ma_Vt, object ps_Dien_Giai, object ps_Ma_Loai1, object ps_Ma_Loai2, object ps_Ma_Loai3, object ii_FilterByUser, string ps_UserName, object ps_Notes, int pi_Posted, int pi_Locked)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { 
                new SqlParameter("p_Ma_DvCs", ps_Subsidiary), new SqlParameter("p_Ngay_Loc", pi_DaysFilter), new SqlParameter("p_Ngay1", pd_Ngay_Ct1), new SqlParameter("p_Ngay2", pd_Ngay_Ct2), new SqlParameter("p_So_Ct1", ps_So_Ct1), new SqlParameter("p_So_Ct2", ps_So_Ct2), new SqlParameter("p_Ma_Ct", ps_Ma_Ct), new SqlParameter("p_Ma_YC", ps_Ma_YC), new SqlParameter("p_Ma_NN", ps_Ma_NN), new SqlParameter("p_Ma_Bp", ps_Ma_Bp), new SqlParameter("p_Ma_Hd", ps_Ma_Hd), new SqlParameter("p_Ma_Vt", ps_Ma_Vt), new SqlParameter("p_Dien_Giai", ps_Dien_Giai), new SqlParameter("p_Ma_Loai1", ps_Ma_Loai1), new SqlParameter("p_Ma_Loai2", ps_Ma_Loai2), new SqlParameter("p_Ma_Loai3", ps_Ma_Loai3), 
                new SqlParameter("p_FilterByUser", ii_FilterByUser), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Notes", ps_Notes), new SqlParameter("p_Posted", pi_Posted), new SqlParameter("p_Locked", pi_Locked)
             };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return table2;
        }

        public void Lock(string ps_UserName, object ps_InvoiceOrder, bool pb_Locked)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Locked", pb_Locked) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "UpdateLockedSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
        }

        public bool NumberExisted(string ps_Subsidiary, bool pb_CheckNewRow, string ps_InvoiceOrder, string ps_InvoiceCode, object pd_Ngay_Ct, object ps_So_Ct)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Moi_Sua", pb_CheckNewRow), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Ma_Ct", ps_InvoiceCode), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_So_Ct", ps_So_Ct), new SqlParameter("p_Check", null) };
            values[6].Direction = ParameterDirection.Output;
            values[6].SqlDbType = SqlDbType.Bit;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CheckSoCtSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                flag = (bool) values[6].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return flag;
        }

        public bool Post(string ps_UserName, object ps_InvoiceOrder, object pi_Posted)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Posted", pi_Posted) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "UpdatePostedSX";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                flag = true;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            return flag;
        }

        public bool Save(bool pb_InvoiceHistory, bool pb_NewChecked, string ps_Subsidiary, string ps_UserName, DataRow po_MasterDataRow, DataTable po_DetailTable)
        {
            bool flag = false;
            foreach (DataRow row in po_DetailTable.Rows)
            {
                if (((row.RowState != DataRowState.Deleted) && !string.IsNullOrEmpty(row["Ma_Vt"].ToString())) && (((decimal) row["So_Luong9"]) != 0M))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                this.Delete(ps_UserName, po_MasterDataRow["Stt"]);
                return false;
            }
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlTransaction transaction = eZConnection.BeginTransaction();
            if (!pb_NewChecked && pb_InvoiceHistory)
            {
                this.SaveHistory(eZConnection, transaction, ps_UserName, po_MasterDataRow["Stt"]);
            }
            flag = true;
            foreach (DataRow row2 in po_DetailTable.Rows)
            {
                row2.EndEdit();
                if (((row2.RowState != DataRowState.Deleted) && !string.IsNullOrEmpty(row2["Ma_Vt"].ToString())) && (((decimal) row2["So_Luong9"]) != 0M))
                {
                    if (((row2.RowState != DataRowState.Added) && (row2.RowState != DataRowState.Modified)) || (this.SaveDetailDataRow(eZConnection, transaction, po_MasterDataRow["Stt"], row2) == 1))
                    {
                        continue;
                    }
                    flag = false;
                    break;
                }
                if (row2.RowState == DataRowState.Deleted)
                {
                    this.DeleteDetailDataRow(eZConnection, transaction, row2["Stt0", DataRowVersion.Original]);
                }
                else
                {
                    this.DeleteDetailDataRow(eZConnection, transaction, row2["Stt0"]);
                }
            }
            if ((flag && (this.SaveMasterDataRow(eZConnection, transaction, pb_NewChecked, ps_Subsidiary, po_MasterDataRow) == 1)) && (this.SaveDetailMaterial(eZConnection, transaction, pb_NewChecked, ps_Subsidiary, po_MasterDataRow) == 1))
            {
                transaction.Commit();
                AppDataAccess.CloseConnection(eZConnection);
                po_DetailTable.AcceptChanges();
                po_MasterDataRow.Table.AcceptChanges();
                return true;
            }
            transaction.Rollback();
            AppDataAccess.CloseConnection(eZConnection);
            return false;
        }

        public int SaveDetailDataRow(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_MasterKey, DataRow row)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt0", row["Stt0"]), new SqlParameter("p_Stt", po_MasterKey), new SqlParameter("p_Stt_Nv", row["Stt_Nv"]), new SqlParameter("p_Ma_Vt", row["Ma_Vt"]), new SqlParameter("p_Ma_Bp", row["Ma_Bp"]), new SqlParameter("p_Ma_Hd", row["Ma_Hd"]), new SqlParameter("p_Dvt", row["Dvt"]), new SqlParameter("p_He_So9", row["He_So9"]), new SqlParameter("p_So_Luong9", row["So_Luong9"]), new SqlParameter("p_So_Luong", row["So_Luong"]), new SqlParameter("p_Stt0_D", row["Stt0_D"]), new SqlParameter("p_Result", SqlDbType.BigInt) };
            values[11].Direction = ParameterDirection.Output;
            values[11].SqlDbType = SqlDbType.Int;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX0_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                num = (int) values[11].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }

        public int SaveDetailMaterial(SqlConnection po_Connection, SqlTransaction po_Transaction, bool pb_NewChecked, string ps_Subsidiary, DataRow row)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", row["Stt"]), new SqlParameter("p_UserName", row["UserName"]), new SqlParameter("p_Result", SqlDbType.BigInt) };
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.Int;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX1_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                num = (int) values[2].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }

        private void SaveHistory(SqlConnection po_Connection, SqlTransaction po_Transaction, string ps_UserName, object ps_InvoiceOrder)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Save_Delete", 1), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Log_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression: ", exception);
            }
        }

        public int SaveMasterDataRow(SqlConnection po_Connection, SqlTransaction po_Transaction, bool pb_NewChecked, string ps_Subsidiary, DataRow row)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { 
                new SqlParameter("p_Moi_Sua", pb_NewChecked), new SqlParameter("p_Stt", row["Stt"]), new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ma_Ct", row["Ma_Ct"]), new SqlParameter("p_Ngay_Ps", row["Ngay_Ps"]), new SqlParameter("p_Ngay_Ct", row["Ngay_Ct"]), new SqlParameter("p_So_Ct", row["So_Ct"]), new SqlParameter("p_Ngay_Ht", row["Ngay_Ht"]), new SqlParameter("p_Ma_YC", row["Ma_YC"]), new SqlParameter("p_Ma_NN", row["Ma_NN"]), new SqlParameter("p_Ma_Bp", row["Ma_Bp"]), new SqlParameter("p_Ma_Hd", row["Ma_Hd"]), new SqlParameter("p_Dien_Giai", row["Dien_Giai"]), new SqlParameter("p_Desc_EN", row["Desc_EN"]), new SqlParameter("p_Ghi_Chu", row["Ghi_Chu"]), new SqlParameter("p_Ma_Loai1", row["Ma_Loai1"]), 
                new SqlParameter("p_Ma_Loai2", row["Ma_Loai2"]), new SqlParameter("p_Ma_Loai3", row["Ma_Loai3"]), new SqlParameter("p_Loai_Ps", row["Loai_Ps"]), new SqlParameter("p_UserName", row["UserName"]), new SqlParameter("p_Posted", row["Posted"]), new SqlParameter("p_Locked", row["Locked"]), new SqlParameter("p_Result", SqlDbType.BigInt)
             };
            values[0x16].Direction = ParameterDirection.Output;
            values[0x16].SqlDbType = SqlDbType.Int;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtSX_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                num = (int) values[0x16].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }
    }
}

